﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace sy2_9
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
        private char Rot13SingleChar(char c)
        {
            if (char.IsUpper(c))
            {
                return (char)((c - 'A' + 13) % 26 + 'A');
            }
            else if (char.IsLower(c))
            {
                return (char)((c - 'a' + 13) % 26 + 'a');
            }
            else
            {
                return c;
            }
        }

        private string Rot13Process(string input)
        {
            char[] chars = input.ToCharArray();
            for (int i = 0; i < chars.Length; i++)
            {
                chars[i] = Rot13SingleChar(chars[i]);
            }
            return new string(chars);
        }

        private void btnEncrypt_Click(object sender, EventArgs e)
        {
            string input = txtInput.Text;
            string result = Rot13Process(input);
            txtInput.Text = result;

            btnEncrypt.Text = btnEncrypt.Text == "加密" ? "解密" : "加密";
        }


        private void btnReset_Click(object sender, EventArgs e)
        {
            txtInput.Text = "";
            btnEncrypt.Text = "加密"; 
        }

    }
}

